/**
 * Created by nieyu on 2016/8/25.
 */
window.onload = function(){
    function immediately(){
        var href = location.href;
        var str = "grade=";
        var arr = href.split("=");
        if(str.indexOf(href) !=-1){

        }
        var grade =  arr[1].substring(4,0)
        for(var i = 0;i<document.getElementById("grd").children.length;i++){

            var op = document.getElementById("grd").children[i].value;
            if(op == grade){
                document.getElementById("grd").value = op
            }


        }
    }
    immediately();
}
var data = [

    {"code" : "工商系", "name" : "工商系",
        "cities" : [{"code" : "财务信息管理", "name" : "财务信息管理"},
            {"code" : "财务信息管理（对口）", "name" : "财务信息管理（对口）"},
            {"code" : "房地产经营与估价", "name" : "房地产经营与估价"},
            {"code" : "工商企业管理", "name" : "工商企业管理"},
            {"code" : "物流管理", "name" : "物流管理"},
            {"code" : "会计学", "name" : "会计学"},
            {"code" : "物流工程", "name" : "物流工程"}]},

    {"code" : "城市学院", "name" : "城市学院",
        "cities" : [{"code" : "汽车检测与维修技术", "name" : "汽车检测与维修技术"}]},

    {"code" : "酒店管理学院", "name" : "酒店管理学院",
        "cities" : [{"code" : "酒店管理（对口）", "name" : "酒店管理（对口）"},
            {"code" : "酒店管理（转录）", "name" : "酒店管理（转录）"},
            {"code" : "酒店管理（高职）", "name" : "酒店管理（高职）"},
            {"code" : "人力资源管理", "name" : "人力资源管理"}]},

    {"code" : "旅游系", "name" : "旅游系",
        "cities" : [{"code" : "导游", "name" : "导游"},
            {"code" : "会展策划与管理", "name" : "会展策划与管理"},
            {"code" : "旅游管理", "name" : "旅游管理"},
            {"code" : "旅游管理（对口）", "name" : "旅游管理（对口）"},
            {"code" : "旅游管理（高职）", "name" : "旅游管理（高职）"},
            {"code" : "涉外旅游", "name" : "涉外旅游"},
            {"code" : "涉外旅游（转录）", "name" : "涉外旅游（转录）"},
            {"code" : "会展经济与管理", "name" : "会展经济与管理"}]},

    {"code" : "烹饪学院", "name" : "烹饪学院",
        "cities" : [{"code" : "烹饪工艺与营养", "name" : "烹饪工艺与营养"},
            {"code" : "烹饪工艺与营养（对口）", "name" : "烹饪工艺与营养（对口）"},
            {"code" : "烹饪工艺与营养（转录）", "name" : "烹饪工艺与营养（转录）"},
            {"code" : "烹饪与营养教育", "name" : "烹饪与营养教育"},
            {"code" : "烹饪与营养教育（对口）", "name" : "烹饪与营养教育（对口）"},
            {"code" : "烹饪与营养教育（高职）", "name" : "烹饪与营养教育（高职）"},
            {"code" : "中西面点工艺", "name" : "中西面点工艺"}]},

    {"code" : "食品学院", "name" : "食品学院",
    "cities" : [{"code" : "食品科学与工程", "name" : "食品科学与工程"},
        {"code" : "食品质量与安全", "name" : "食品质量与安全"},
        {"code" : "西餐工艺", "name" : "西餐工艺"},
        {"code" : "西餐工艺（对口）", "name" : "西餐工艺（对口）"},
        {"code" : "西餐工艺（A）", "name" : "西餐工艺（A）"},
        {"code" : "西餐工艺（B）", "name" : "西餐工艺（B）"}]},

    {"code" : "外语系", "name" : "外语系",
        "cities" : [{"code" : "商务英语", "name" : "商务英语"},
            {"code" : "旅游英语", "name" : "旅游英语"},
            {"code" : "旅游英语（转录）", "name" : "旅游英语（转录）"},
            {"code" : "商务日语", "name" : "商务日语"},
            {"code" : "应用法语", "name" : "应用法语"},
            {"code" : "日语", "name" : "日语"}]},

    {"code" : "乡村建设与规划系", "name" : "乡村建设与规划系",
        "cities" : [{"code" : "园林工程技术", "name" : "园林工程技术"}]},

    {"code" : "信息与工程系", "name" : "信息与工程系",
        "cities" : [{"code" : "信息管理与信息系统", "name" : "信息管理与信息系统"},
            {"code" : "信息管理与信息系统（A）", "name" : "信息管理与信息系统（A）"},
            {"code" : "信息管理与信息系统（B）", "name" : "信息管理与信息系统（B）"},
            {"code" : "电子商务", "name" : "电子商务"},
            {"code" : "电子商务（对口）", "name" : "电子商务（对口）"},
            {"code" : "电子商务（转录）", "name" : "电子商务（转录）"},
            {"code" : "计算机信息管理", "name" : "计算机信息管理"},
            {"code" : "计算机信息管理（对口）", "name" : "计算机信息管理（对口）"},
            {"code" : "楼宇智能化工程技术", "name" : "楼宇智能化工程技术"},
            {"code" : "楼宇智能化工程技术（对口）", "name" : "楼宇智能化工程技术（对口）"},
            {"code" : "数字媒体技术", "name" : "数字媒体技术"},
            {"code" : "建筑电气与智能化", "name" : "建筑电气与智能化"}]},

    {"code" : "艺术系", "name" : "艺术系",
        "cities" : [{"code" : "环境设计", "name" : "环境设计"},
            {"code" : "人物形象设计", "name" : "人物形象设计"},
            {"code" : "装潢艺术设计", "name" : "装潢艺术设计"},
            {"code" : "风景园林", "name" : "风景园林"},
            {"code" : "园林工程技术", "name" : "园林工程技术"}]},

    {"code" : "运动与休闲学院", "name" : "运动与休闲学院",
        "cities" : [{"code" : "高尔夫服务与管理", "name" : "高尔夫服务与管理"},
            {"code" : "休闲体育", "name" : "休闲体育"},
            {"code" : "运动休闲服务与管理", "name" : "运动休闲服务与管理"}]}

];

// 获取院系select
var proSelect = document.getElementById("department");
for (var i = 0; i < data.length; i++)
{
    var json = data[i];
    var option = new Option(json.name, json.code, false, false);
    proSelect.add(option);
}
// 为proSelect绑定onChange事件
proSelect.onchange = function(){

    var citySelect = document.getElementById("major");
    // 在下次选择院系之前先清空专业下拉列表
    for (var i = citySelect.length - 1; i > 0; i--)
    {
        citySelect.remove(i);
    }
    for (var i = 0; i < data.length; i++)
    {
        var json = data[i];
        if (json.code == this.value)
        {
            // 取专业
            var cities = json.cities;
            for (var j = 0; j < cities.length; j++)
            {
                // 获取其中的json
                var temp = cities[j];
                var option = new Option(temp.name, temp.code, false, false);
                citySelect.add(option);
            }
        }
    }
};

